package day09.Map.HashMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Text {
    public static void main(String[] args) {
        HashMap<Student, String> hm = new HashMap<Student, String>();

        //创建学生对象
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("张曼玉", 35);
        Student s3 = new Student("王祖贤", 33);
        Student s4 = new Student("王祖贤", 33);

        //把学生添加到集合
        hm.put(s1, "西安");
        hm.put(s2, "武汉");
        hm.put(s3, "郑州");
        hm.put(s4, "北京");
        Set<Student> s = hm.keySet();
        for (Student key : s) {
            String value = hm.get(key);
            System.out.println(key+"---"+value);
        }
        System.out.println("-----------");
        Set<Map.Entry<Student, String>> entries = hm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"----"+value);
        }
        System.out.println("-----------");
        hm.forEach((Student key,String value)->{
            System.out.println(key+"----"+value);
        });
    }
}
